package com.prj.ufdm.cloud.zipken;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.RestTemplate;

import zipkin2.Span;
import zipkin2.reporter.Reporter;

@SpringBootApplication
@EnableAsync
public class SleuthApplication implements EnvironmentAware {
	
    private static Environment env;
	
	@Override
	public void setEnvironment(Environment environment) {
		env = environment;
	}
	
	public static void main(String[] args) {
		SpringApplication.run(SleuthApplication.class, args); 
		System.out.println("\n Sleuth " + env.getProperty("server.port") + " 启动成功........"); 
	}
	
	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

	// Use this for debugging (or if there is no Zipkin server running on port 9411)
	@Bean
	@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
	public Reporter<Span> spanReporter() {
		return Reporter.CONSOLE;
	}
}
